package com.javaEE.gamepigeon.controller;


import com.javaEE.gamepigeon.entity.School;
import com.javaEE.gamepigeon.service.SchoolService;
import com.javaEE.gamepigeon.util.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "学校接口")
@RestController
@RequestMapping("/school")
public class SchoolController {

    @Autowired
    SchoolService schoolService;


//    @ApiImplicitParams({
//            @ApiImplicitParam(name = "schoolName",value = "学校名称",paramType = "query")
//    })
    @ApiOperation("添加学校")
    @PostMapping("/add")
    public Result addSchool(@RequestBody School school){
        if(schoolService.saveOrUpdate(school)){
            return Result.success("添加成功!");
        }else {
            return Result.error("添加失败！");
        }
    }

    @ApiOperation("删除学校")
    @DeleteMapping("/{id}")
    public Result deleteSchool(@PathVariable  Integer id){
        if(schoolService.removeById(id)){
            return Result.success("删除成功!");
        }else {
            return Result.error("删除失败！");
        }
    }

    @ApiOperation("查询所有学校")
    @GetMapping("/query")
    public List<School> querySchool(){
        return schoolService.list();
    }

//    @ApiImplicitParams({
//            @ApiImplicitParam(name = "newName",value = "学校的新名称",paramType = "query"),
//            @ApiImplicitParam(name = "schoolId",value = "学校对应的Id",paramType = "query")
//    })
//    @ApiOperation("根据id修改学校名称")
//    @GetMapping("/update")
//    public Result updateSchool(Integer schoolId, String newName){
//        if(schoolService.updateSchool(schoolId,newName)){
//            return Result.success("更新成功!");
//        }else {
//            return Result.error("更新失败！");
//        }
//    }

}
